<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2022/1/12
  Time: 15:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>车辆管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link type="text/css" rel="stylesheet"  href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>


<%--添加--%>
<form class="layui-form" lay-filter="branchForm" id="branchForm" action="##"style="display: none" >
    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">车牌号:</label>
            <div class="layui-input-block">
                <input type="text" id="carnumber"  name="carnumber" lay-verify="carnumber" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">汽车类型：</label>
            <div class="layui-input-inline">
                <input type="text" id="cartype" name="cartype" lay-verify="cartype" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">汽车颜色：</label>
                <div class="layui-input-inline">
                    <input type="text" id="color" name="color" lay-verify="color" autocomplete="off" class="layui-input">
                </div>
            </div>
            <%--            <input type="text" name="goodsid" style="display: none">--%>
            <%--            <div class="layui-collapse">--%>
            <%--                <div class="layui-colla-item">--%>
            <%--                    </div>--%>
            <%--                </div>--%>
            <%--            </div>--%>
            <%--            <label class="layui-form-label">上传图片：</label>--%>
            <%--            <input class="layui-btn layui-btn-sm" type="file" id="carimg"style="width:190px" name="carimg">--%>
            <%--            <br>--%>
            <%--            <br>--%>
            <div class="layui-inline">
                <label class="layui-form-label">汽车价格：</label>
                <div class="layui-input-inline">
                    <input type="text" id="price" name="price" lay-verify="price" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">出租价格：</label>
                <div class="layui-input-inline">
                    <input type="text" id="rentprice" name="rentprice" lay-verify="rentprice" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">租车押金：</label>
                <div class="layui-input-inline">
                    <input type="text" id="deposit" name="deposit" lay-verify="deposit" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">汽车描述：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="description" name="description" lay-verify="description" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <label class="layui-form-label">是否出租：</label>
                <div class="layui-input-block">
                    <input type="radio"  name="isrenting" value="0" title="已出租" checked="">
                    <input type="radio"  name="isrenting" value="1" title="未出租">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn " id="tijiao" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>

</form>



<%--修改--%>
<form class="layui-form" lay-filter="branchForm1" id="branchForm1" action="##"style="display: none" >
    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">车牌号:</label>
            <div class="layui-input-block">
                <input type="text" id="carnumber1"  name="carnumber" lay-verify="carnumber" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">汽车类型：</label>
            <div class="layui-input-inline">
                <input type="text" id="cartype1" name="cartype" lay-verify="cartype" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">汽车颜色：</label>
                <div class="layui-input-inline">
                    <input type="text" id="color1" name="color" lay-verify="color" autocomplete="off" class="layui-input">
                </div>
            </div>
            <%--            <input type="text" name="goodsid" style="display: none">--%>
            <%--            <div class="layui-collapse">--%>
            <%--                <div class="layui-colla-item">--%>
            <%--                </div>--%>
            <%--            </div>--%>
            <%--        </div>--%>
            <%--        <label class="layui-form-label">上传图片：</label>--%>
            <%--        <input class="layui-btn layui-btn-sm" type="file" id="carimg1"style="width:190px" name="carimg">--%>
            <%--        <br>--%>
            <%--        <br>--%>
            <div class="layui-inline">
                <label class="layui-form-label">汽车价格：</label>
                <div class="layui-input-inline">
                    <input type="text" id="price1" name="price" lay-verify="price" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">出租价格：</label>
                <div class="layui-input-inline">
                    <input type="text" id="rentprice1" name="rentprice" lay-verify="rentprice" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">租车押金：</label>
                <div class="layui-input-inline">
                    <input type="text" id="deposit1" name="deposit" lay-verify="deposit" autocomplete="off" class="layui-input">
                </div>
            </div>
                <div class="layui-inline">
                    <label class="layui-form-label">汽车描述：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="description1" name="description" lay-verify="description" autocomplete="off" class="layui-input">
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上传图片：</label>
                <div class="layui-input-inline">
                    <input class="layui-btn layui-btn-sm" type="file" id="carimg1"style="width:190px" name="carimg">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否出租：</label>
                <div class="layui-input-block">
                    <input type="radio"  name="isrenting" value="0" title="已出租" checked="">
                    <input type="radio"  name="isrenting" value="1" title="未出租">
                </div>
            </div>
                <div class="layui-input-block">
                    <button class="layui-btn " id="tijiao1" lay-submit lay-filter="formDemo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>

</form>

<%--头部搜索栏--%>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">车牌号:</label>
            <div class="layui-input-inline">
                <input type="text" name="carnumber" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">颜色：</label>
            <div class="layui-input-inline">
                <input type="text" name="color"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">汽车类型：</label>
            <div class="layui-input-inline">
                <input type="text" name="cartype"  autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-inline">
                <input type="text" name="description"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">是否出租：</label>
            <div class="layui-input-block">
                <input type="radio" name="isrenting" value="0" title="已出租" checked="">
                <input type="radio" name="isrenting" value="1" title="未出租">
            </div>
        </div>
        <div class="layui-form-item" align="center">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="demo1">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>


<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>--%>
        <%--        {{#  if(${sessionScope.staff.branchid} == 12138){ }}--%>
        <button class="layui-btn layui-btn-sm"  lay-event="addBranch">新增</button>
        <button class="layui-btn layui-btn-sm" lay-event="plsc">批量删除</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="selt">查看原图</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['tree', 'util','table','jquery','form'], function() {
        var table = layui.table;
        var tree = layui.tree;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.jquery;
        var form = layui.form;

        //添加表单的搜索监听事件
        form.on('submit(demo1)',function(data){
            //表格数据重新渲染。
            table.reload('tb',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //按照什么进行查找
                    "carnumber": data.field.carnumber,
                    "color": data.field.color,
                    "cartype": data.field.cartype,
                    "description": data.field.description,
                    "isrenting": data.field.isrenting,
                }
            })
        });
        //监听头部工具栏
        table.on('toolbar(test)',function (obj) {
            var event=obj.event;
            var checkStatus = table.checkStatus(obj.config.id);
            if (event==='addBranch'){
                $("#branchForm")[0].reset();
                layer.open({
                    type:1,
                    area:['400px','400px'],
                    content: $("#branchForm"),
                    titlel:'添加用户'
                })
            }else if (event==='plsc'){
                if (checkStatus.data.length>0){
                    var data = checkStatus.data;
                    var flag=1;
                    var aaa=${sessionScope.user.type};
                    // $.each(data,function (i) {
                    //     if(1!=aaa) {
                    //         flag = 0;
                    //         layer.msg("对不起,你没有权限")
                    //     }
                    // })
                    if (flag==1){
                        layer.confirm('进行批量删除吗？', function(index){
                            $.ajax({
                                url: "${pageContext.request.contextPath}/busCar/dels",
                                type:"post",
                                dataType: "json",
                                // contentType:'application/json;charset=utf-8',
                                data:{"carnumber":JSON.stringify(data)},
                                //将一个 JavaScript 对象或值转换为 JSON 字符串
                                success: function (result) {
                                    layer.closeAll();
                                    if (result.code==2000) {
                                        //重载表格
                                        table.reload("tb");
                                        layer.msg(result.msg);
                                    } else {
                                        layer.msg(result.msg);
                                    }
                                }
                            });
                        });
                    }

                } else {
                    alert("请选择要批量删除的数据！")
                }
            }
        });
        table.render({
            id:'tb',
            elem: '#test'
            //,id:"test"
            , url: '${pageContext.request.contextPath}/busCar/listByCondition'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , title: '员工数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'carnumber', title:'车牌号'}
                ,{field:'cartype', title:'汽车类型'}
                ,{field:'color', title:'颜色'}
                ,{field:'price', title:'汽车价格'}
                ,{field: 'rentprice', title:'租车价格'}
                ,{field: 'deposit', title:'押金'}
                ,{field: 'isrenting', title:'是否出租',templet:function (data) {
                        return data.isrenting==0?"已出租":"未出租";
                    }}
                ,{field: 'description', title:'描述'}
                , {
                    field: 'carimg', title: '汽车图片', height: 50, templet: function (d) {
                        var a = d.carimg
                        return "<img src='" + a + "' style='width: 100px;height: 50px'>"
                    }
                }
                ,,{fixed: 'right', title:'操作', toolbar: '#barDemo', }
            ]]
            , page: true
            , limit: 5 //默认每页显示5条
            , limits:[5,10,15]
        });

        //增加
        form.on('submit(formDemo)', function(data){
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            $.ajax({
                url:"${pageContext.request.contextPath}/busCar/add",
                //contentType: 'application/json;charset=UTF-8',
                data:$("#branchForm").serialize(),
                type:'post',
                success:function (result){
                    if (result.code == 1) {
                        table.reload('tb')
                        layer.msg(result.msg)
                    }else {
                        //layer.closeAll();
                        layer.msg(result.msg)
                    }
                    //table.reload('tb')
                },
                dataType:'json'
            })
        });


        //批量删除


        //修改
        form.on('submit(formDemo1)', function(data){
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            $.ajax({
                url:"${pageContext.request.contextPath}/busCar/update",
                //contentType: 'application/json;charset=UTF-8',
                data:$("#branchForm1").serialize(),
                type:'post',
                success:function (result){
                    if (result.code == 1) {
                        table.reload('tb')
                        layer.msg(result.msg)
                    }else {
                        //layer.closeAll();
                        layer.msg(result.msg)
                    }
                    //table.reload('tb')
                },
                dataType:'json'
            })
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                var flag = 1;
                if (flag==1){
                    layer.confirm('真的删除吗?', function(index){
                        $.ajax({
                            type:'post',
                            url:'${pageContext.request.contextPath}/busCar/delete',
                            data:{'carnumber':data.carnumber},
                            dataType: 'json',
                            success:function (result){
                                layer.closeAll();
                                if (result.code == 1) {
                                    table.reload('tb')
                                    layer.msg(result.msg)
                                }else {
                                    layer.msg(result.msg)
                                }
                                //table.reload('tb')
                            }
                        })

                        layer.close(index);

                    });
                }
            } else if(obj.event === 'edit') {
                $("#branchForm1")[0].reset();
                layer.open({
                    type:1,
                    title:'修改信息',
                    area:['500px','500px'],
                    offset:'0px',
                    anim:4,
                    content:$("#branchForm1"),
                })
                console.log(data)
                form.val('branchForm1',data);
            }else if(obj.event==='selt') {
                layer.open({
                    type: 1,
                    title:"查看图片",
                    area:["682px","480px"],
                    content:'<img class="layui-upload-img" id="demo1" img src="'+data.carimg+'">'
                });

            }
        });
    });
</script>

</body>
</html>
